package com.jm10010

import kotlin.math.PI

class Power {
    private val factorG = 9.80665F
    private val factorKgfMPerS = 75

    private fun lbf2kg(lbf: Double): Double {
        return 0.45359237 * lbf
    }

    private fun ft2m(ft: Double): Double {
        return 0.3048F * ft
    }

    private fun getFactorBComm(): Double {
        return (PI * 2) * 144 / 60
    }

    /**
     * P = W/t = Fd/t
     */
    fun getFactorBMechanical(): Double {
        return this.getFactorBComm() * 180 * 12
    }

    fun getFactorBImperial(): Double {
        return this.getFactorBComm() / 60 * 180 * 12
    }

    private fun getFactorBKW(): Double {
        return this.getFactorBComm() / 60 * this.factorG * this.lbf2kg(180.0) * this.ft2m(12.0) / 1000
    }

    fun bhp2kW(hp: Double): Double = this.getFactorBKW() * hp

    fun kW2bhp(kW: Double): Double = kW / this.getFactorBKW()

    private fun getFactorKW(): Float {
        return this.factorKgfMPerS * factorG / 1000
    }

    /**
     * Also PS
     */
    fun hp2kW(hp: Double): Double = this.getFactorKW() * hp

    fun kW2hp(kW: Double): Double = this.getFactorKW().toDouble() / this.getFactorKW()
}